#ifndef PUB_SUB_H
#define PUB_SUB_H

#include <stdint.h>
#include <stdlib.h> 
#include <string.h> 

#define MAX_TOPIC_LENGTH 32         //一个话题的最大长度
#define MAX_SUBSCRIBER_NUM 10       //最大订阅者数量
#define QUEUE_SIZE 1                //消息队列大小

typedef struct mqt
{
    void* queue[QUEUE_SIZE];            //消息队列
    uint8_t data_len;                   //数据长度
    uint8_t head;                       //头指针
    uint8_t tail;                       //尾指针
    uint8_t size;
    struct mqt* next_sub;     //下一个订阅者
} Subscriber_message_t;

typedef struct ent
{
    char topic[MAX_TOPIC_LENGTH + 1];   //话题
    uint8_t data_len;                    //数据长度
    Subscriber_message_t* first_sub;    //第一个订阅者  
    struct ent* next_pub;      //下一个发布者
    uint8_t pub_init_flag;              //发布者初始化标志
} Publisher_message_t;

Subscriber_message_t* subscriber_init(char* topic, uint8_t data_len);
Publisher_message_t* publisher_init(char* topic, uint8_t data_len);

uint8_t PubPushMessage(Publisher_message_t* pub, void* data);
uint8_t SubGetMessage(Subscriber_message_t* sub, void* data);
#endif
